<?php #Корзина
/* if(empty($_POST))
	$_POST=$_GET;
	$elog=false;
	$conn->echoQ=true; */

$basket_id = getBasketId() ? getBasketId() : setBasketId();
	$_POST['installation'] = isset( $_POST['installation']) ? $_POST['installation'] : '';
	$_POST['vip_service'] = isset( $_POST['vip_service']) ? $_POST['vip_service'] : '';

    $set = '';
    if( $_POST['vip_service'] && $_POST['installation'] != '' )
        $set = ', `count_inst` = `count_inst` + 1, `inst` = 1'.( $_POST['vip_service'] ? ', `count_vip` = `count_vip` + 1, `vip` = 1' : '' );
    elseif( $_POST['installation'] == 'on' || $_POST['vip_service'] == 'on' && $_POST['installation'] == '' )
        $set = ( $_POST['vip_service'] ? ', `count_vip` = `count_vip` + 1, `vip` = 1' : '' );

	$conn->query( 'SELECT * FROM `store_basket_products` WHERE `basket_id` = '.$basket_id.' AND `product_code` = '.$_POST['product_code'] );
	if( $conn->rowCount() ) {
		$conn->query('UPDATE `store_basket_products` SET `count` = `count` + 1 '.$set.' WHERE `basket_id` = '.$basket_id.' AND `product_code` = '.$_POST['product_code'] );
		
		$add_upd_product = array (
			'add_upd' => 'update',
			'product_code' => $_POST['product_code'],
		);
	}
	else {
		$conn->query( 'INSERT INTO `store_basket_products` SET	`basket_id`	= '.$basket_id.', `product_code` = '.$_POST['product_code'].', `count` = 1 '.$set );
		
		$conn->query("SELECT * FROM store_products_cache WHERE `product_code` = '{$_POST['product_code']}'");
		$new_product = $conn->fetch();
		
		$new_product_img 		= getImageSrcNew( $_POST['product_code'] , $size = 'd' );
		$new_product_fullname 	= $new_product->prefix.' '.$new_product->brand.' <strong>'.$new_product->name.'</strong>';

		$new_product_html = '
			<li class="shopping-cart__list__item orders__products" product_code="'.$_POST['product_code'].'">
				<div class="shopping-cart__list__item__inner">
					<ul>
						<li>
							<div class="global-photo">										
								<img src="'.$new_product_img.'" alt="">
							</div>
							<div class="shopping-cart__list__description">
								<h2>
									<a href="'.$new_product->url.'">'.$new_product_fullname.'</a>
								</h2>
							</div>
						</li>
						<li>
							<dl>
								<dt>Кол-во:</dt>
								<dd>
									<ul class="number-navi">
										<li class="number-navi__less arrow">
											<span class="arrow back">-</span>
										</li>
										<li>
											<input type="text" class="select_count product" value="1">
										</li>
										<li class="number-navi__more arrow">
											<span class="arrow forward">+</span>
										</li>
									</ul>
								</dd>
							</dl>									
						</li>
						<li>
							<dl class="shopping-cart__list__price">
								<dt>Цена:</dt>
								<dd>'.$new_product->price_retail.' руб</dd>
							</dl>
						</li>
					</ul>
					<span class="shopping-cart__list__delete delete">
						<span>Удалить</span>
					</span>	
				</div>
			</li>
		';
		
		$add_upd_product = array (
			'add_upd' => 'insert',
			'new_product_html' => $new_product_html,
		);
	}
	
	$counts	= getCountProduct( $basket_id );
	$costs	= getTotalCosts( $basket_id );
	displayMessage( $counts , $costs, $add_upd_product );